package com.zy.utils;

import java.util.HashSet;
import java.util.Random;

public class DataBuildUtils {
    private static final int SIZE = 10;
    private static final int RANGE = 90;

    //10-99
    public static int[] getRandomSortArray() {
        return getRandomSortArray(SIZE);
    }

    public static int[] getRandomSortArray(int size) {
        Random random = new Random();
        int[] list = new int[size];
        HashSet<Integer> hashSet = new HashSet<>();
        for (int index = 0; index < size; index++) {
            int num = 0;
            do {
                num = random.nextInt(RANGE) + 10;
            } while (hashSet.contains(num));
            hashSet.add(num);
            list[index] = num;
        }
        return list;
    }

    public static int[] getRandomSortArray(int size, int range) {
        float d = (float) range / (float) size;
        if (d == 0) {
            d = 1;
        }
        int[] list = new int[size];
        float base = 1;
        for (int index = 0; index < size; index++) {
            list[index] = (int) base;
            base += d;
        }
        getRandomSortArrayV2(list);
        return list;
    }

    public static void getRandomSortArrayV2(int[] sort) {
        Random random = new Random();
        int length = sort.length;
        for (int index = 0; index < length; index++) {
            int newIndex = random.nextInt(length);
            int tmp = sort[index];
            sort[index] = sort[newIndex];
            sort[newIndex] = tmp;
        }
    }
}